package com.migo.api;

import com.migo.annotation.IgnoreAuth;
import com.migo.entity.AppDownloadEntity;
import com.migo.mongo.entity.ReleaseNoteMongo;
import com.migo.mongo.service.ReleaseNoteMongoService;
import com.migo.oss.OSSFactory;
import com.migo.service.AppDownloadService;
import com.migo.service.SysOssService;
import com.migo.utils.R;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class ApiAppDownloadController {

    @Autowired
    OSSFactory ossFactory;

    @Autowired
    private SysOssService sysOssService;

    @Autowired
    private AppDownloadService appDownloadService;


    @Autowired
    private ReleaseNoteMongoService releaseNoteMongoService;

    /**
     * App 下载
     */
    @IgnoreAuth
    @RequestMapping(value = "appDownLoad", produces = "application/json;charset=utf-8;")
    public R appDownLoad(@RequestParam Map<String, String> params) {
            List<AppDownloadEntity> appDownloadList = appDownloadService.queryList(new HashedMap());
            return R.ok().put("data",appDownloadList.get(0));
    }



    /**
     * App release note
     */
    @IgnoreAuth
    @RequestMapping(value = "queryReleaseNote", produces = "application/json;charset=utf-8;")
    public R queryReleaseNote(@RequestParam Map<String, String> params) {
        Query query = Query.query(new Criteria());
        List<ReleaseNoteMongo> releaseNoteMongoList = releaseNoteMongoService.list(query);
        return R.ok().put("data",releaseNoteMongoList);
    }



}
